import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import footer from '../views/footer.vue'


Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'home',
    component: HomeView,
    meta: {
      isRoot: true,
      keep: true
    }
  },
  {
    path: '/release',
    name: 'release',

    component: () =>
      import('../views/release.vue'),
 
  },
  {
    path: '/my',
    name: 'my',

    component: () =>
      import('../views/my.vue'),

  }, {
    path: '/reg',
    name: 'reg',

    component: () =>
      import('../views/reg.vue')
  }, , {
    path: '/orgetPassword',
    name: 'orgetPassword',

    component: () =>
      import('../views/orgetPassword.vue')
  },
  {
    path: '/login',
    name: 'login',

    component: () =>
      import('../views/login.vue')
  },
  {
    path: '/login1',
    name: 'login1',

    component: () =>
      import('../views/login1.vue')
  },
  {
    path: '/userInfo1',
    name: 'userInfo1',

    component: () =>
      import('../views/userInfo/userInfo1.vue'),
    meta: {
      auth: true
    }
  },
  {
    path: '/favoritesList',
    name: 'favoritesList',

    component: () =>
      import('../views/favoritesList.vue'),
    meta: {
      auth: true
    }
  },
  {
    path: '/publish',
    name: 'publish',

    component: () =>
      import('../views/publish.vue'),
      meta: {
        isRoot: true
      }
  },
  {
    path: '/my1',
    name: 'my1',

    component: () =>
      import('../views/my1.vue'),
    meta: {
      isRoot: true
    }
  },
  {
    path: '/reg1',
    name: 'reg1',

    component: () =>
      import('../views/reg1.vue')
  },
  {
    path: '/details',
    name: 'details',

    component: () =>
      import('../views/details.vue')
  },
  {
    path: '/search',
    name: 'search',

    component: () =>
      import('../views/search/search.vue')
  },
  {
    path: '/userInfo',
    name: 'userInfo',

    component: () =>
      import('../views/userInfo.vue')
  },
  {
    path: '/article',
    name: 'article',

    component: () =>
      import('../views/article/article.vue')
  },
  {
    path: '/changePassword',
    name: 'changePassword',

    component: () =>
      import('../views/changePassword.vue')
  },

  {
    path: '/about',
    name: 'about',

    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/myRelease',
    name: 'myRelease',
    component: () => import('../views/myRelease.vue'),
    meta: {
      auth: true
    }
  },

  {
    path: '/searchList',
    name: 'searchList',

    component: () => import('../views/search/list.vue')
  }, {
    path: '/index',
    name: 'index',

    component: () => import('../views/index.vue')
  },
  {
    path: '/edit',
    name: 'edit',
    component: () => import('../views/edit.vue')
  }
]

const router = new VueRouter({
  routes
})
// 全局前置守卫
import store from "@/store";
import {
  Toast
} from 'vant'
router.beforeEach((to, from, next) => {
  let uid = store.state.uid;
  if (to.meta.auth) {
    if (uid) {
      // 是登录状态

      next()

    } else {
      Toast('请先登录')
      setTimeout(v => {
        router.replace('/login1')
      }, 1000)
    }

  } else {
    next()

  }









})
export default router